package com.songcan.basics.core.controller;


import cn.hutool.core.map.MapUtil;
import com.songcan.basics.core.service.CommonFileService;
import com.songcan.basics.core.service.SmsService;
import com.songcan.common.contans.ImageType;
import com.songcan.common.contans.SmsTypeEnum;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.IOException;

@RestController
@AllArgsConstructor
@RequestMapping("rest/common")
public class FileController {

     private final CommonFileService commonFileService;
     private final SmsService smsService;


     @PostMapping("/file")
     public Object addImage(@NotNull(message = "上传文件不能为空")MultipartFile imagesFile,@NotNull(message = "类型不能为空")ImageType imageType) throws IOException {
         return MapUtil.of("id",commonFileService.addFile(imagesFile, imageType));
     }

    /**
     * 发送验证码
     * @param mobile
     * @param smsTypeEnum
     */
    @PostMapping("/sms_code")
    public void sendMessage(String mobile, SmsTypeEnum smsTypeEnum){
        smsService.sendMessage(smsTypeEnum,mobile);
    }


}
